package com.qfedu.openplateform.manager.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.openplateform.manager.entity.AjaxMessage;
import com.qfedu.openplateform.manager.entity.UserToken;
import com.qfedu.openplateform.manager.service.TokenService;
import com.qfedu.openplateform.manager.util.JsonResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sys/token")
public class TokenController {

    @Autowired
    private TokenService tokenService;

    @RequestMapping("/table")
    public JsonResultUtil tokenTable(
            @RequestParam(value = "page",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "limit",required = false,defaultValue = "5")Integer pageSize
    ){
        PageHelper.startPage(pageNum,pageSize);
        List<UserToken> userList = tokenService.getToken();
        PageInfo<UserToken> pageInfo = new PageInfo<UserToken>(userList);
        JsonResultUtil jsonResultUtil = JsonResultUtil.success();
        jsonResultUtil.setCount(pageInfo.getTotal());
        jsonResultUtil.setData(pageInfo.getList());

        return jsonResultUtil;
    }
    @RequestMapping("/del")
    public AjaxMessage del(Integer[] ids){
        System.out.println(ids.length);
        tokenService.del(ids);
        return new AjaxMessage(true,"success");
    }
    @RequestMapping("/update")
    public AjaxMessage update(UserToken userToken){
        tokenService.update(userToken);
        return new AjaxMessage(true,"success");
    }
}
